﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layuimini/css/public.css" rel="stylesheet" />
    <link href="~/layui/css/soulTable.css" rel="stylesheet" />
    <style>


    </style>
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset">
                <legend>收发存表</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action=""  lay-filter="example">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">开始日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="BeginDate" autocomplete="off" class="layui-input" name="BeginDate" readonly="readonly">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">结束日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="EndDate" autocomplete="off" class="layui-input" name="EndDate" readonly="readonly">
                                </div>
                            </div>
                            <div class="layui-inline" style="display:none;">
                                <label class="layui-form-label">流程卡</label>
                                <div class="layui-input-inline">
                                    <select name="BillNameID" lay-search id="BillNameID">
                                        @Html.Raw(ViewBag.BillName)
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>
            <table class="layui-hide" id="myTable" lay-filter="myTable"></table>
        </div>
    </div>
    <script src="~/layui/layui.js"></script>
    <script src="~/layuimini/js/lay-config.js"></script>
    <script>
        layui.config({
            base: '/layui/extend/'
        }).extend({
            soulTable: 'soulTable'
        }).use(['form', 'table', 'laydate', 'soulTable'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                laydate = layui.laydate,
                soulTable = layui.soulTable;
        @*var end = laydate.render({
            elem: '#AllotDate', //选择器结束时间
            format: 'yyyy-MM',
            type: 'month',
            value: '@DateTime.Now.AddMonths(-1).ToString("yyyy-MM")',
            showBottom: false, //关闭底部框 去掉取消、确定、清空按钮
            // 选择年份或者月份都会关闭
             change: function (value, date, endDate) { //监听日期被切换
                lay('#endTime').val(value);
                 if ($(".layui-laydate").length) {
                     $(".layui-laydate").remove();
                 }
             },
            //选择月份即选中关闭  年份扔可以左右点击选择
             change: function (value, date, endDate) { //监听日期被切换
                 lay('#endTime').val(value);
                 $('.laydate-month-list').on('click','li',function () {//利用的事件委托
                     $('.layui-laydate').remove()
                  })
             },
            done: function (value, date) {
                start.config.max = {
                        year:value ? date.year : 3099,
                        month: date.month - 1, //关键
                        date: date.date,
                        hours: 0,
                        minutes: 0,
                        seconds: 0
                    }
            }
        });*@

            laydate.render({
                  elem: '#BeginDate'
                , format: 'yyyy-MM-dd'
                , type: 'date'
                , trigger: 'click'
                , value: '@DateTime.Now.AddMonths(0).ToString("yyyy-MM-01")'
            });
            laydate.render({
                elem: '#EndDate'
                , format: 'yyyy-MM-dd'
                 , type: 'date'
               , trigger: 'click'
                 , value: '@DateTime.Now.AddMonths(0).ToString("yyyy-MM-dd")'
            });

        table.render({
            elem: '#myTable',
            method: 'post',
            url: '@Url.Action("ShouFaChunReportAsync", "Report")',
            request: {
                pageName: 'PageIndex' //页码的参数名称，默认：page
               , limitName: 'PageSize' //每页数据量的参数名，默认：limit
            },
            where: {
                BeginDate: form.val('example').BeginDate,
                EndDate: form.val('example').EndDate,
                BillNameID: 3,
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', { layEvent: 'export', icon: 'layui-icon-export', title: '刷新' }, 'print'],
            cols: [[
                { field: 'GoodsName', title: '产品名称', rowspan: 2 },
                //{ field: 'GoodsCode', title: '产品编号', rowspan: 2 },
                { field: 'TaskTime', title: '本月工时', rowspan: 2 },
                { field: 'InitQty', title: '期初在产', rowspan: 2 },
                { field: 'OutQty', title: '本期投片', rowspan: 2 },
                { field: 'FailQty', title: '本期废片', rowspan: 2 },
                { field: 'InQty', title: '本期完工', rowspan: 2 },
                { field: 'EndQty', title: '期末在产', rowspan: 2 },
                { field: '', title: '当月主材领料数量', colspan: 3, align: 'center' },
               //{ field: 'MeritPay', title: '绩效工资' },
            ], [
                { field: 'ZhuoQty', title: '座' },
                { field: 'MaoQty', title: '帽' },
                { field: 'XinQty', title: '芯片' },
            ]],
            limits: [10, 20, 30, 50, 100, 100000000],
            limit: 20,
            page: false,
            //skin: 'line',
            //totalRow: true,
            height: 'full-170',
            //size:'sm',
            excel: {filename: '复杂表头导出.xlsx'}
            ,done: function () {
                soulTable.render(this)
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            RefreshTable();
            return false;
        });

        /**
         * toolbar监听事件
         */
        var myTable = table.on('toolbar(myTable)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加工艺手册',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['890px', '600px'],
                    content: '@Url.Action("ProcedureEdit", "Procedure")',
                    end: function () {
                        RefreshTable();

                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('myTable')
                    , data = checkStatus.data;
                if (data.length == 0) {
                    layer.msg('请选择您要删除的数据！', { icon: 5, time: 2000 });
                    return;
                }

                var arr = [];
                for (var i = 0; i < data.length; i++) {
                    arr.push(data[i].ID);
                }

                var ids = arr.join(",");


                layer.confirm('您确定要删除所选数据吗', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url: '@Url.Action("ProcedureDelAsync", "Procedure")',
                        type: "post",
                        dataType: "json",
                        data: { IDs: ids },
                        success: function (data) {
                            //Info,Success,Warning,Error
                            var type = data.Type;
                            if (type == 1) {
                                layer.msg(data.Content,
                                    {
                                        icon: 6, time: 2000
                                    },
                                    function () {
                                        RefreshTable();
                                    });
                            } else {
                                layer.msg(data.Content, { icon: 5, time: 2000 });
                            }
                        }
                    });
                }, function () {
                    return;
                });
            } else if (obj.event === 'export') {  // 监听删除操作
                soulTable.export('myTable', {
                    filename: '收发存表.xlsx'
                });
            } else if (obj.event === 'state') {  // 监听删除操作
                var checkStatus = table.checkStatus('myTable')
                    , data = checkStatus.data;
                if (data.length == 0) {
                    layer.msg('请选择您要修改上架状态的数据！', { icon: 5, time: 2000 });
                    return;
                }

                var arr = [];
                for (var i = 0; i < data.length; i++) {
                    arr.push(data[i].ID);
                }

                var ids = arr.join(",");


                layer.confirm('您确定要修改所选数据的上架状态吗', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url: '@Url.Action("ModefyProcedureStateAsync", "Procedure")',
                        type: "post",
                        dataType: "json",
                        data: { IDs: ids },
                        success: function (data) {
                            //Info,Success,Warning,Error
                            var type = data.Type;
                            if (type == 1) {
                                layer.msg(data.Content,
                                    {
                                        icon: 6, time: 2000
                                    },
                                    function () {
                                        RefreshTable();
                                    });
                            } else {
                                layer.msg(data.Content, { icon: 5, time: 2000 });
                            }
                        }
                    });
                }, function () {
                    return;
                });
            }
        });

        //监听表格复选框选择
            table.on('checkbox(myTable)', function (obj) {
            console.log(obj)
        });

            table.on('tool(myTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '修改工艺手册',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['830px', '535px'],
                    content: '@Url.Action("ProcedureEdit", "Procedure")' + '?ID=' + data.ID,
                    end: function () {
                        RefreshTable();
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('您确定要删除所选数据吗', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url: '@Url.Action("ProcedureDelAsync", "Procedure")',
                        type: "post",
                        dataType: "json",
                        data: { IDs: data.ID },
                        success: function (obj) {
                            //Info,Success,Warning,Error
                            var type = obj.Type;
                            if (type == 1) {
                                layer.msg(obj.Content,
                                    {
                                        icon: 6, time: 2000
                                    },
                                    function () {
                                        RefreshTable();
                                    });
                            } else {
                                layer.msg(obj.Content, { icon: 5, time: 2000 });
                            }
                        }
                    });
                }, function () {
                    return;
                });
            } else if (obj.event === 'state') {
                layer.confirm('您确定要修改所选数据的上架状态吗', {
                    btn: ['是的', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url: '@Url.Action("ModefyProcedureStateAsync", "Procedure")',
                        type: "post",
                        dataType: "json",
                        data: { IDs: data.ID },
                        success: function (obj) {
                            //Info,Success,Warning,Error
                            var type = obj.Type;
                            if (type == 1) {
                                layer.msg(obj.Content,
                                    {
                                        icon: 6, time: 2000
                                    },
                                    function () {
                                        RefreshTable();
                                    });
                            } else {
                                layer.msg(obj.Content, { icon: 5, time: 2000 });
                            }
                        }
                    });
                }, function () {
                    return;
                });
            } else if (obj.event === 'aui') {

                var index = layer.open({
                    title: '工艺手册详情',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['1200px', '600px'],
                    content: '@Url.Action("ProcedureDetailsList", "Procedure")' + '?ProcedureID=' + data.ID,
                    end: function () {
                        RefreshTable();
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });
        function RefreshTable() {
            table.reload('myTable', {
                where: {
                    BeginDate: form.val('example').BeginDate,
                    EndDate: form.val('example').EndDate,
                    BillNameID: 3,
                }
            }, 'data');

        }

    });
    </script>
</body>
</html>